<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctx!}/assets/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx!}/assets/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx!}/assets/css/animate.css" rel="stylesheet">
    <link href="${ctx!}/assets/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="${ctx!}/assets/css/admin-main.css" rel="stylesheet">
    <style>
        .row {
            margin-top: 5px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="tabe_div" style="padding-right: 0">
    <p class="p_line text_ient"></p>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-1"><h3>底图配置</h3></div>
    </div>
    <div class="row">
        <div class="col-sm-offset-1 col-sm-2">
            <form enctype="multipart/form-data" id="imageForm">
                <input class="btn-primary" type="file" name="file">
                <input type="hidden" name="type" value="0">
                <input type="hidden" name="projectId" value="${project.id}">
            </form>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-offset-1 col-sm-2">
            <input type="button" class="btn-primary" id="picUpload" onclick="upload('#imageForm')" value="上传图片">
        </div>
    </div>
    <div class="row">
        <div class="col-sm-offset-1 col-sm-2">
            <img style="height: 100px; width: auto" alt="" id="image">
        </div>
    </div>
    <div class="row">
        <div class="col-sm-1"><h3>主页略图配置</h3></div>
    </div>

    <div class="row">
        <div class="col-sm-offset-1 col-sm-2">
            <form enctype="multipart/form-data" id="panelForm">
                <input class="btn-primary" type="file" name="file">
                <input type="hidden" name="type" value="1">
                <input type="hidden" name="projectId" value="${project.id}">
            </form>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-offset-1 col-sm-2">
            <input type="button" class="btn-primary" onclick="upload('#panelForm')" value="上传图片">
        </div>
    </div>
    <div class="row">
        <div class="col-sm-offset-1 col-sm-2">
            <img style="height: 100px; width: auto" alt="" id="panel">
        </div>
    </div>
    <div hidden="hidden" id="panel-edit" class="row">
        <div class="col-sm-offset-1 col-sm-2">
            <input type="button" class="btn-primary" onclick="map_edit();" value="配置地图位置">
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <form class="form-horizontal m-t" id="frm" method="post" action="${ctx!}/admin/project/edit">
                <input type="hidden" id="id" name="id" value="${project.id}">
                <input type="hidden" id="image" name="image" value="${project.image}">
                <input type="hidden" id="panel" name="panel" value="${project.panel}">
                <div class="form-group">
                    <div class="col-sm-8 col-sm-offset-1 btn-box">
                        <button class="btn btn-primary" onclick="back()" type="reset">返回</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="${ctx!}/assets/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctx!}/assets/js/bootstrap.min.js?v=3.3.6"></script>
<!-- 自定义js -->
<script src="${ctx!}/assets/js/content.js?v=1.0.0"></script>
<!-- jQuery Validation plugin javascript-->
<script src="${ctx!}/assets/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${ctx!}/assets/js/plugins/validate/messages_zh.min.js"></script>
<script src="${ctx!}/assets/js/plugins/layer/layer.min.js"></script>
<script src="${ctx!}/assets/js/plugins/layer/laydate/laydate.js"></script>
<script type="text/javascript">
    function map_edit() {
        window.location.href = "${ctx!}/admin/project/panel/${project.id}";
    }

    function back() {
        $("#navbar-header-title", window.parent.document).html("项目信息");
        window.location.href = '${ctx!}/admin/project/index/';
    }

    function loadimg(img_id, url) {
        $(img_id).attr('src', "${ctx}" + url);
    }

    function upload(formId) {
        var formData = new FormData($(formId)[0]);
        $.ajax({
            url: '${ctx!}/admin/project/image/upload',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                data = eval('(' + data + ')')
                console.log(data)
                if (data.success) {
                    data = data.data
                    layer.msg("上传成功")
                    if (formId == '#imageForm') {
                        loadimg("#image", data.url)
                    } else {
                        loadimg("#panel", data.url)
                    }
                } else {
                    layer.msg(data.message)
                }
            },
            error: function (error) {
                layer.msg("网络异常")
            }
        })
    }

    $(document).ready(function () {
        <#if (project.image)??>
        loadimg("#image", "${project.image}");
        </#if>
        <#if (project.panel)??>
        loadimg("#panel", "${project.panel}");
        $("#panel-edit").removeAttr("hidden");
        </#if>
        $("#frm").validate({
            messages: {},
            submitHandler: function (form) {
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: "${ctx!}/admin/project/display/edit",
                    data: $(form).serialize(),
                    success: function (msg) {
                        layer.msg(msg.message, {time: 2000}, function () {
                            location.reload();
                        });
                    }
                });
            }
        });
    });
</script>
</body>
</html>
